// 导入验证规则模块
const joi = require('joi')

// 验证规则
/**
 * string() 必须为字符串
 * alphanum() 只能包含a-zA-Z0-9的字符串
 * min(length) 最小长度
 * max(length) 最大长度
 * required() 必填项 不能为undefined
 * pattern(正则表达式) 必须符合正则表达式的规则
 * dataUri 指的是验证是否位base64格式的字符串
 */

// 商品信息的验证规则
const product_name = joi.string().required()
const detail = joi.string().required()
const price = joi.string().required()
const product_img = joi.string().dataUri().required()
const product_num = joi.string().required()
const category = joi.string().required()

// 分类的验证规则
const id = joi.string().min(1).required()
const cate_name = joi.string().required()
const cate_alias = joi.string().required()

// 发布商品
exports.publishinfo_schema = { 
    body:{ 
        product_name,
        detail,
        price,
        product_img,
        product_num,
        category,
    }
}

// 更新商品
exports.updateinfo_schema = { 
    body:{ 
        id,
        product_name,
        detail,
        price,
        product_img,
        product_num,
        category,
    }
}

// 添加分类
exports.addcategory_schema = { 
    body:{ 
        cate_name,
        cate_alias
    }
}

// 修改分类
exports.updatecategory_schema = { 
    body:{ 
        id,
        cate_name,
        cate_alias
    }
}


// dataUri指的是验证是否位base64格式的字符串
const img_url = joi.string().dataUri().required()
const img_describe = joi.string().required()

exports.uploadimages_schema = {
    body: {
        img_url,
        img_describe
    }
}

const name = joi.string().required()
const phone = joi.string().max(11).required()
const address = joi.string().required()
exports.addAddress_schema = {
    body : {
        name,
        phone,
        address
    }
}